package com.blink.curator.recipe.distributed;

import com.blink.base.BaseTestSample;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.atomic.AtomicValue;
import org.apache.curator.framework.recipes.atomic.DistributedAtomicInteger;
import org.apache.curator.retry.RetryNTimes;
import org.junit.jupiter.api.Test;

/**
 * <Description> 分布式计数器</Description>
 * <ClassName> DistributedAtomicIntegerSample</ClassName>
 *
 * @Author liuxianzhao
 * @Date 2018年01月13日 18:29
 */
public class DistributedAtomicIntegerSample extends BaseTestSample {

    @Test
    public void testDistributedAtomicInteger() throws Exception {
        CuratorFramework client = getZkCurator();
        client.start();
        final String distatomicint_path = "/curator_recipes_distatomicint_path";
        DistributedAtomicInteger atomicinteger =
                new DistributedAtomicInteger(client, distatomicint_path,
                        new RetryNTimes(3, 1000));
        AtomicValue<Integer> rc = atomicinteger.add(8);
        logger.info("result: " + rc.succeeded() + "," + rc.postValue());
        sleep();
    }
}
